<script type="text/html" template>
    <link rel="stylesheet" href="{{ layui.setter.base }}style/css/home/edit-alert.css">
</script>
<style> 
    .label-required-next:after {
            top: 6px;
            left: 5px;
            color: red;
            content: '*';
            position: absolute;
            margin-left: 4px;
            font-weight: 700;
            line-height: 1.8em;
        } </style>
    <div class="alert-box"> 
        <form class="form layui-form"> 
            <div class="layui-form-item">
                <label class="layui-form-label labelinp label-required-next" och="documentName">文档名称：</label>
                <div class="layui-input-block">
                    <input type="text" name='tcDocName' class="tcDocName" autocomplete="off" ></input> 
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label labelinp label-required-next" och="documentType">文档类型：</label>
                <div class="layui-input-block" id="documentType" style="height: 25px; " >   
                    <input type="text" disabled ></input> 
                </div> 
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label labelinp label-required-next"  och="unittype">设备型号：</label>  
                <div class="layui-input-block"> 
                    <input type="text" id="unittypeinp" autocomplete="off" name="unittype"></input> 
                    <div class="boxsearch">
                        <ul class="ulsearch"> 
                        </ul>
                    </div> 
                </div> 
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label labelinp"  och="supplier">供应商：</label>
                <div class="layui-input-block">
                    <input type="text" disabled class="supplier" name='supplier'> </input> 
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label labelinp"  och="DEVseries">设备系列：</label>
                <div class="layui-input-block">
                    
                    <input type="text" disabled class="DEVseries"  name='DEVseries'> </input>
                </div> 
            </div>
          
            <div class="layui-form-item">
                <label class="layui-form-label labelinp label-required-next"  och="keyword">关键字：</label>
                <div class="layui-input-block">
                    <input type="text" name="keyword" class="keyword" required lay-verify="required" autocomplete="off" class="layui-input" value="">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label labelinp label-required-next"  och="accessory">附件：</label>
                <div class="btn-box layui-input-block">
                    <div class="formtitle" style="width: 120px;overflow: auto;height: 100px;"> 
                    </div>   
                    <button class="add layui-btn layui-btn-xs layui-btn-radius"  type="button" id="addexport">
                        <span>添加更多</span>
                        <span class="export layui-icon"></span>
                    </button>
                </div>
            </div>  
           
        </form>
        <div class="footer layui-btn-container">
            <!-- lay-submit lay-filter="*" -->
            <button   class="btn1 layui-btn layui-btn-radius layui-btn-primary" id="confirm">确定</button>
            <button class="btn2 layui-btn layui-btn-radius layui-btn-primary" id="cancel">取消</button>
        </div>
    </div> 
<div class="alert-box" id="TEST123" >
    <div class="alert_title" style="text-align: center;">相关文档选择</div> 
    <div id="testtree" class="demo-tree demo-tree-box" style="
    height: 300px;
    overflow: auto;  padding: 10px 60px;
"></div>
    <div class="footer">
        <button class="btn1 layui-btn layui-btn-radius layui-btn-primary" id="documentType_btn">确认</button>
        <button  class="btn2 layui-btn layui-btn-radius layui-btn-primary">取消</button>
    </div>
</div>   
    <script>   
        layui.use(["admin", "form", "user", "api", "upload", "utill","jquery", "table", "form"], function() {
   
            var form = layui.form,
                layer = layui.layer,
                $ = layui.$,
                admin = layui.admin,
                view = layui.view,
                api = layui.api,
                table = layui.table,
                setter = layui.setter,
                laytpl = layui.laytpl,
                utill = layui.utill,
                form = layui.form,  
                upload=layui.upload,
                element = layui.element;
                var tree = layui.tree; 
                var setter = layui.setter;  
                var en='../../../src/lang/en.js',
                    cn='../../../src/lang/cn.js' 
                var dqEnglish=layui.sessionData('English').English
                var url=dqEnglish?cn:en 
                var filesArr=[] 
                var tableobj=layui.sessionData('demo').tableobj
                var olist= null
                var demoListView = $('.formtitle')  
                $.getScript(url,function(){ 
                    var labelinp=$('.labelinp') 
                    var odata=pageindex.compile  
                    for(item in odata){ 
                        labelinp.each(function(i){ 
                            if($(this).attr('och')==item){ 
                                $(this).html(odata[item]+'：') 
                            } 
                        }); 
                    }   
                })    
                layui.sessionData('alert_tf', null); //删除alert_tf表
                var documentType_id=''
                var documentType_name=''
                var uploadInst = upload.render({
                    elem: '#addexport'
                    ,url: api.host+'/do/upload.json' ,
                    headers:{ 
                        'token': layui.sessionData(setter.tableName).token 
                    }
                    ,accept: 'file' 
                    ,bindAction: ''
                    ,choose: function(obj){   
                    }
                    ,done: function(res, index, upload){  
                        filesArr.push(res.data)   
                        var tr=$(['<li id="upload-'+  res.data.tcFileId +'"><span>'+ res.data.tcFileName +res.data.tcFileType +'</span><button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button></li>'].join(''));   
                            //删除
                            tr.find('.demo-delete').on('click', function(){  
                                    filesArr = filesArr.filter(({ tcFileId }) => tcFileId !== res.data.tcFileId); 
                                    tr.remove(); 
                            }); 
                            demoListView.append(tr); 
                    }
                });
          
            $('body').off('input propertychange', '#unittypeinp').on('input propertychange', '#unittypeinp', function (e) {
                var url= api.host+'/do/selectSeries1.json'
                    var data={
                        param:$(this).val()
                    } 
                    ajax(url, 'get', data, function(res){ 
                        var list=res.data 
                        var lishhtml='' 
                        if(list.length>0){
                            for(var i=0;i<list.length;i++){
                                lishhtml+=`<li class='olist' pmc03=`+list[i].pmc03+ ` tcSeriesId=`+list[i].tcSeriesId+ ` pmc01=`+list[i].pmc01 +` tcSeriesName=`+list[i].tcSeriesName+ ` fii02=` +list[i].fii02 +` tcModelId=`+ list[i].tcModelId+`>`+ list[i].pmc01+' '+ list[i].fii02+ ' '+ list[i].tcModelId+`</li>`
                            }
                            $('.ulsearch').html(lishhtml)
                            $('.boxsearch').addClass('addsearchborder')
                        } 
                        olist= $('.olist') 
                        olist.on('click', function() {
                            var fii02= $(this).attr('fii02')
                            var pmc01= $(this).attr('pmc01')
                            var pmc03= $(this).attr('pmc03')
                            var tcModelId= $(this).attr('tcModelId')
                            var tcSeriesId= $(this).attr('tcSeriesId')
                            var tcSeriesName= $(this).attr('tcSeriesName') 
                            $('.DEVseries').val(tcSeriesName) 
                            $('.supplier').val(pmc03) 
                            $('#unittypeinp').val(fii02)   
                            $('.DEVseries').attr('tcSeriesId',tcSeriesId) 
                            $('.supplier').attr('pmc01',pmc01) 
                            $('#unittypeinp').attr('tcModelId',tcModelId)  
                            $('.boxsearch').removeClass("addsearchborder")   
                        });
                    }) 
			})
            $('body').off('click', '#confirm').on('click', '#confirm', function (e) {
               
                var tcSeriesId= $('.DEVseries').attr('tcSeriesId') 
                    var pmc01= $('.supplier').attr('pmc01')
                    var tcModelId= $('#unittypeinp').attr('tcModelId')  
                    var obj={ 
                        "tcDocModelid": tcModelId?tcModelId:'',
                        "tcDocName": $('.tcDocName').val(),  
                        "tcDocCatgid":$('#documentType').attr('tcDocCatgid'), 
                        "tcDocPmc01":pmc01?pmc01:'',
                        "tcDocSeriesid":tcSeriesId?tcSeriesId:'',
                        "tcEamFile":  filesArr,
                        "tcKeyword":  $('.keyword').val()
                        }   
                    var url= api.host+'/do/insertdoc.json'
                    if(obj.tcDocName!='' && obj.tcDocPmc01!=''&& obj.tcDocSeriesid!=''&& obj.tcKeyword!='' && filesArr.length>0){
                        ajax(url, 'POST', JSON.stringify(obj), function(res){ 
                            if(res.code==0){ 
                                // var index = parent.layer.getFrameIndex(window.name);
                                // parent.layer.close(index);
                                // layer.close( sessionStorage.getItem('indexone'))
                                layui.sessionData('alert_tf',{
                                    key: 'state'
                                    ,value: '1'
                                })
                                var index = parent.layer.getFrameIndex(window.name);  
                                parent.layer.close(index); 
                                layer.close( sessionStorage.getItem('indexone'))
                                layui.sessionData('BJtf', {
                                    key:'truefalse',
                                    value:true
                                }) 
                            }else{
                                layer.msg(res.message, {icon: 5}); 
                            } 
                        })
                    }else{
                        layer.msg('缺少必填项', {icon: 5});  
                    }  
			})    
            $('body').off('click', '#cancel').on('click', '#cancel', function (e) {
                var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index); 
                    layer.close( sessionStorage.getItem('indexone'))
                    layui.sessionData('BJtf', {
                        key:'truefalse',
                        value:false
                    }) 
			}) 
            $('body').off('click', '#documentType').on('click', '#documentType', function (e) {
                admin.popup({
                          title: '文档类型',
                          area: ['400px', '480px'],
                          id: 'LAY-popup-content-tags-2',
                          success: function (layero, index) { 
                            sessionStorage.setItem('index', index)
                            view(this.id).render('home/my_home/one').done(function () {   
                            });
                          }, 
                        end: function () {  
                            var one_data=layui.sessionData('one_data') 
                            JSON.stringify(one_data) != "{}"?  $('#documentType').html(one_data.odata.title) :''
                            JSON.stringify(one_data) != "{}"? $('#documentType').attr('tcDocCatgid',one_data.odata.tcCatgId) :''
                            }  
                        }); 
			})
            $('body').off('click', '#documentType_btn').on('click', '#documentType_btn', function (e) {
               
                $('#documentType').html(documentType_name) 
                $('#documentType').attr('tcDocCatgid',documentType_id)  
                $('#TEST123').css('display','none')
			}) 
            function ajax (url, type, data, callback){ 
                    $.ajax({ 
                        headers: { 
                            'Content-Type':'application/json',
                            'token': layui.sessionData(setter.tableName).token 
                        }, 
                        async: false, 
                        dataType: "json",
                        jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
                        url: url,
                        type: type, 
                        data: data,
                        success: callback
                    });
                } 
            });
    </script> 